; Music of Cobra's Arc (1986) (Dinamic) (Luis Mezquita Raya)
; Ripped by Megachur the 09/07/2008

; Need System Vectors

	write "COBRA'SA.BIN"

music_date_rip	equ &0978
music_adr	equ &a27f
first_theme	equ 0
last_theme	equ 2	;  0 -> 2 (3rd theme don't work)

	read "music_header_v1_0.asm"

;
.init_music
;
	cp #04	; init music	a = 0 -> 2 (3rd theme don't work)
	ret nc
	ex af,af'
	ld a,(la5bc)
	and a
	ret nz
	ex af,af'
	add a
	add a
	add a
	ld l,a
	ld h,#00
	ld de,l10fe
	add hl,de
	ld de,la5bf
	ld bc,#0008
	ldir
	ld hl,(la5bf)
.la29e
	ld a,(hl)
	and a
	jr z,la2aa
	inc hl
	ld c,(hl)
	inc hl
	call #bd34
	jr la29e
;
.play_music
.la2aa
;
	ld hl,(la5c1)
	ld de,(la5c3)
	ld ix,(la5c5)
.la2b5
	xor a
	ld (la5be),a
	ld a,(hl)
	cp #ff
	jp z,la354
	cp #64
	jr c,la2ea
	cp #72
	jr nc,la2ea
	inc hl
	ld c,(hl)
	sub #64
	cp #08
	jr c,la2e3
	cp #0b
	jr nc,la2e3
	sub #08
	push hl
	push de
	ld l,a
	ld h,#00
	ld de,la5c7
	add hl,de
	ld (hl),c
	pop de
	pop hl
	jr la2e6
.la2e3
	call #bd34
.la2e6
	inc hl
	jp la2b5
.la2ea
	bit 7,a
	jr z,la309
	push hl
	push de
	and #7f
	ld b,a
	ld hl,#0000
	ld de,#0200
.la2f9
	add hl,de
	djnz la2f9
	ld (la5ca),hl
	pop de
	pop hl
	inc hl
	ld a,(hl)
	ld (la5cc),a
	inc hl
	jr la2b5
.la309
	call la366
.la30c
	ld a,#01
	ld (la5be),a
	ld a,(de)
	cp #ff
	jr z,la35a
	call la366
.la319
	ld a,#02
	ld (la5be),a
	ld a,(ix+#00)
	cp #ff
	jr z,la360
	call la366
	push hl
	ld a,(la5cc)
	ld b,a
.la32d
	ld hl,(la5ca)
.la330
	dec hl
	ld a,h
	or l
	jr nz,la330
	djnz la32d
	pop hl
	call #bb1b
	inc hl
	inc de
	inc ix
	jp nc,la2b5
;
.stop_music
;
	xor a
	ld b,#0e
.la345
	push bc
	push af
	ld c,#00
	call #bd34
	pop af
	pop bc
	inc a
	cp #0f
	jr nz,la345
	ret
.la354
	ld hl,(la5c1)
	jp la2b5
.la35a
	ld de,(la5c3)
	jr la30c
.la360
	ld ix,(la5c5)
	jr la319
.la366
	ld b,a
	and a
	jr z,la3ab
	ld a,(la5be)
	push hl
	push de
	ld l,a
	ld h,#00
	ld de,la5c7
	add hl,de
	ld c,(hl)
	pop de
	pop hl
	add #08
	push bc
	call #bd34
	pop bc
	push hl
	push de
	ld a,b
	add a
	ld l,a
	ld h,#00
	ld de,l1450
	add hl,de
	ld a,(hl)
	inc hl
	ld h,(hl)
	ld l,a
	call la395
	pop de
	pop hl
	ret
.la395
	ld a,(la5be)
	add a
	push af
	push hl
	push bc
	ld c,l
	call #bd34
	pop bc
	pop hl
	pop af
	inc a
	push bc
	ld c,h
	call #bd34
	pop bc
	ret
.la3ab
	ld a,(la5be)
	add #08
	ld c,#00
	push bc
	call #bd34
	pop bc
	ret
.la5bc
	db #00
.la5c3 equ $ + 6
.la5c1 equ $ + 4
.la5bf equ $ + 2
.la5be equ $ + 1
	db #04,#00,#00,#00,#00,#00,#00,#00
.la5cc equ $ + 7
.la5ca equ $ + 5
.la5c7 equ $ + 2
.la5c5
	db #00,#00,#0c,#10,#0d,#00,#00,#00
	db #00,#ff,#ff,#f9,#b7,#fb,#b7,#00
	db #81,#fb,#95,#ff,#00,#00,#f1,#00
	db #00,#81,#16,#96,#00,#00,#00,#0d
	db #1a,#0c,#18,#09,#12,#10,#14,#01
	db #02,#0b,#0f,#08,#03,#06,#02,#0b
	db #0d,#0b,#18,#0b,#23,#0b,#2e,#0b
	db #39,#0b,#44,#0b,#02,#0e,#0d,#0e
	db #18,#0e,#23,#0e,#2e,#0e,#39,#0e
	db #44,#0e,#00,#02,#01,#0d,#01,#02
	db #04,#0d,#04,#02,#07,#0d,#07,#23
	db #0b,#23,#0e,#00,#0d,#07,#05,#07
	db #05,#0d,#06,#00,#00,#00,#00,#07
	db #07,#0a,#05,#07,#08,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00
	
	;org #10fe
.l10fe
	dw l11b0,l11b9,l1264,l1305
	dw l1116,l111f,l1152,l1181
	dw l13a5,l13ae,l13e3,l1414
.l1116
	db #07,#38,#0b,#64,#0c,#01,#0d,#0e
.l111f equ $ + 1
	db #00,#b9,#01,#6d,#10,#00,#00,#00
	db #00,#2e,#30,#31,#30,#33,#31,#30
	db #31,#2e,#30,#31,#30,#33,#31,#30
	db #31,#2a,#2e,#30,#31,#2c,#30,#31
	db #33,#2e,#31,#33,#31,#35,#33,#31
	db #33,#2a,#2e,#30,#31,#2c,#30,#31
.l1152 equ $ + 4
	db #33,#2e,#00,#ff,#3d,#3d,#3d,#3d
	db #3d,#3d,#3d,#3d,#3d,#3d,#3d,#3d
	db #3d,#3d,#3d,#3d,#3d,#3d,#3d,#3d
	db #3a,#3a,#3a,#3a,#3c,#3c,#3c,#3c
	db #3d,#3d,#3d,#3d,#3d,#3d,#3d,#3d
	db #3d,#3a,#3a,#3a,#3a,#3c,#3c,#3c
.l1181 equ $ + 3
	db #3c,#3c,#ff,#22,#22,#22,#22,#22
	db #22,#22,#22,#22,#22,#22,#22,#22
	db #22,#22,#22,#22,#22,#22,#22,#1e
	db #1e,#1e,#1e,#20,#20,#20,#20,#22
	db #22,#22,#22,#22,#22,#22,#22,#22
	db #1e,#1e,#1e,#1e,#20,#20,#20,#20
	db #00,#ff
.l11b0
	db #07,#38,#0b,#00,#0c,#03,#0d,#0e
.l11b9 equ $ + 1
	db #00,#9b,#01,#6d,#10,#00,#3a,#3d
	db #3a,#38,#3a,#3d,#3a,#38,#3a,#3d
	db #3d,#3a,#3a,#38,#38,#35,#38,#35
	db #33,#35,#38,#35,#33,#35,#38,#38
	db #35,#35,#38,#38,#3a,#3d,#3a,#38
	db #3a,#3d,#3a,#38,#3a,#3d,#3d,#3a
	db #3a,#38,#38,#35,#38,#35,#33,#35
	db #38,#35,#33,#35,#35,#38,#38,#3a
	db #3a,#9f,#01,#2e,#30,#31,#33,#34
	db #34,#35,#00,#2e,#30,#31,#33,#34
	db #34,#35,#00,#38,#38,#36,#36,#38
	db #38,#36,#36,#35,#36,#38,#36,#35
	db #35,#3a,#3c,#3d,#3f,#40,#40,#41
	db #00,#3a,#3c,#3d,#3f,#40,#40,#41
	db #00,#42,#42,#41,#41,#40,#40,#41
	db #41,#3d,#40,#3d,#3c,#3a,#6d,#0d
	db #9f,#01,#35,#3a,#38,#36,#3a,#38
	db #36,#38,#36,#35,#35,#35,#34,#35
	db #34,#31,#34,#35,#35,#35,#35,#3a
	db #38,#36,#3a,#38,#36,#38,#36,#35
	db #35,#35,#34,#35,#31,#34,#31,#30
.l1264 equ $ + 4
	db #2e,#2e,#2e,#ff,#2e,#2e,#2e,#2e
	db #2e,#2e,#2e,#2e,#2e,#2e,#2e,#2e
	db #2e,#2e,#2e,#2e,#24,#24,#24,#24
	db #24,#24,#24,#24,#24,#24,#24,#24
	db #24,#24,#24,#2e,#2e,#2e,#2e,#2e
	db #2e,#2e,#2e,#2e,#2e,#2e,#2e,#2e
	db #2e,#2e,#24,#24,#24,#24,#24,#24
	db #24,#24,#24,#2c,#2c,#24,#2e,#2e
	db #2e,#2e,#2e,#2e,#2e,#2e,#2e,#2e
	db #2e,#2e,#2e,#2e,#2e,#2e,#2e,#2e
	db #24,#24,#24,#24,#24,#24,#24,#24
	db #24,#24,#24,#24,#24,#24,#2e,#2e
	db #2e,#2e,#2e,#2e,#2e,#2e,#2e,#2e
	db #2e,#2e,#2e,#2e,#2e,#2e,#24,#24
	db #24,#24,#24,#24,#24,#24,#24,#24
	db #2e,#2e,#2e,#41,#46,#44,#42,#46
	db #44,#42,#44,#42,#41,#41,#41,#40
	db #41,#40,#3d,#40,#41,#41,#41,#41
	db #46,#44,#42,#46,#44,#42,#44,#42
	db #41,#41,#41,#40,#41,#3d,#40,#3d
.l1305 equ $ + 5
	db #3c,#3a,#3a,#3a,#ff,#22,#22,#22
	db #22,#22,#22,#22,#22,#22,#22,#22
	db #22,#22,#22,#22,#22,#1d,#1d,#1d
	db #1d,#1d,#1d,#1d,#1d,#1d,#1d,#1d
	db #1d,#1d,#1d,#22,#22,#22,#22,#22
	db #22,#22,#22,#22,#22,#22,#22,#22
	db #22,#22,#1d,#1d,#1d,#1d,#1d,#1d
	db #1d,#1d,#1d,#1d,#20,#20,#22,#22
	db #22,#22,#22,#22,#22,#22,#22,#22
	db #22,#22,#22,#22,#22,#22,#22,#22
	db #1d,#1d,#1d,#1d,#1d,#1d,#1d,#1d
	db #1d,#1d,#1d,#1d,#1d,#1d,#22,#22
	db #22,#22,#22,#22,#22,#22,#22,#22
	db #22,#22,#22,#22,#22,#22,#1d,#1d
	db #1d,#1d,#1d,#1d,#1d,#1d,#1d,#1d
	db #22,#22,#22,#29,#2e,#2c,#2a,#2e
	db #2c,#2a,#2c,#2a,#29,#29,#29,#28
	db #29,#28,#25,#28,#29,#29,#29,#29
	db #2e,#2c,#2a,#2e,#2c,#2a,#2c,#2a
	db #29,#29,#29,#28,#29,#25,#28,#25
.l13a5 equ $ + 5
	db #24,#22,#22,#22,#ff,#07,#38,#0b
.l13ae equ $ + 6
	db #00,#0c,#02,#0d,#0e,#00,#c7,#02
	db #6d,#10,#00,#00,#00,#3d,#3d,#3b
	db #39,#38,#38,#00,#3b,#3b,#39,#38
	db #34,#34,#00,#39,#39,#38,#36,#31
	db #31,#2f,#34,#31,#31,#00,#00,#31
	db #39,#39,#00,#31,#36,#36,#00,#2f
	db #31,#00,#00,#2f,#34,#31,#31,#31
.l13e3 equ $ + 3
	db #00,#00,#ff,#20,#20,#20,#20,#20
	db #20,#20,#20,#20,#20,#1c,#1c,#1c
	db #1c,#1c,#1c,#1c,#25,#25,#25,#25
	db #25,#25,#25,#1c,#20,#20,#20,#20
	db #20,#1c,#1c,#1c,#20,#25,#25,#25
	db #1c,#1c,#1c,#1c,#1c,#1c,#20,#20
.l1414 equ $ + 4
	db #20,#20,#20,#ff,#19,#19,#19,#19
	db #19,#19,#19,#19,#19,#19,#21,#21
	db #21,#21,#21,#21,#21,#1e,#1e,#1e
	db #1e,#1e,#1e,#1e,#17,#19,#19,#19
	db #19,#19,#21,#21,#21,#19,#1e,#1e
	db #1e,#17,#17,#17,#17,#17,#17,#19
	db #19,#19,#19,#19,#ff,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
.l1450
	dw #0eee,#0e18,#0d4d,#0c8e
	dw #0bda,#0b2f,#0a8f,#09f7
	dw #0968,#08e1,#0861,#07e9
	dw #0777,#070c,#06a7,#0647
	dw #05ed,#0598,#0547,#04fc
	dw #04b4,#0470,#0431,#03f4
	dw #03bc,#0386,#0353,#0324
	dw #02f6,#02cc,#02a4,#027e
	dw #025a,#0238,#0218,#01fa
	dw #01de,#01c3,#01aa,#0192
	dw #017b,#0166,#0152,#013f
	dw #012d,#011c,#010c,#00fd
	dw #00ef,#00e1,#00d5,#00c9
	dw #00be,#00b3,#00a9,#009f
	dw #0096,#008e,#0086,#007f
	dw #0077,#0071,#006a,#0064
	dw #005f,#0059,#0054,#0050
	dw #004b,#0047,#0043,#003f
	dw #003c,#0038,#0035,#0032
	dw #002f,#002d,#002a,#0028
	dw #0026,#0024,#0022,#0020
	dw #001e,#001c,#001b,#0019
	dw #0018,#0016,#0015,#0014
	dw #0013,#0012,#0011,#0010

;
;.init_music	; added by Megachur
;
;	call real_init_music
;	ld hl,evt_bloc
;	ld bc,#8100
;	ld de,play_music
;	jp #bcd7	; call play_music every CRT interrupt
;evt_bloc
;	db #00,#00,#00,#00,#00,#00
;	dw #0000
;
.game_name
	db "Cobra's Arc",0
.game_year
	db "1986",0
.game_publisher
	db "Dinamic",0
.music_author
	db "Luis Mezquita Raya",0
.music_comment
	db "",0

	read "music_end_v1_0.asm"
